#!/bin/bash

# ------------ local variabeles ------------
. /etc/sipman.conf
#echo "$REMOTE_USER"
export REMOTE_USER


printLongIp ()
{
IP=$1
COUNT=1
for NUM in `echo "$IP" | awk -F. '{ print $1 " " $2 " " $3 " " $4 }'`
do
  if [ "${#NUM}" -eq "1" ]; then
    printf 00$NUM
  elif [ "${#NUM}" -eq "2" ]; then
    printf 0$NUM
  else
    printf $NUM
  fi
  if [ "$COUNT" -lt "4" ]; then
    printf "."
  fi
  COUNT=`expr $COUNT + 1`
done
}

readFile ()
{
FILE=$1
if [ -f $FILE ]; then
  cat $FILE
else
  printf "-"
fi
}

dispNodeConfig ()
{
local IPADDR=$1
local NETWORK=$2
  NETDIR=$SIM_IPDATAB/`echo $IPADDR | sed 's#\.#/#g'`
  if [ ! -d $NETDIR ]; then
    echo "$NETDIR not found."
  else
    NODETYPE=`readFile $NETDIR/nodetype.txt`
    SIPMANRECTYPE=`readFile $NETDIR/sipmanrectype.txt`
    MANAGEMENTTYPE=`readFile $NETDIR/managementtype.txt`
    SNMPMAC=`readFile $NETDIR/snmpmac.txt`
    DHCPMAC=`readFile $NETDIR/dhcpmacaddr.txt`
    NSTATUS=`readFile $NETDIR/pollstatus.txt`
    DNSNAME=( `readFile $NETDIR/dnsname.txt` )
    HOSTNAME=`readFile $NETDIR/hostname.txt`
    SNMPOID=`readFile $NETDIR/snmpoid.txt`
    INTNUM=`readFile $NETDIR/intnum.txt`
    COMM=`readFile $NETDIRsnmpcomm.txt`
    CFGDATE=`readFile $NETDIR/snmpinfodate.txt`
    COMMENT="`readFile $NETDIR/comment.txt`"
    if [ "$SIPMANRECTYPE" = "-" ] || [ "$SIPMANRECTYPE" = "old" ]; then
      echo "<A HREF=$SCRIPT_NAME?config+removeEntry+$IPADDR+$NETWORK>Remove</A>"
    fi
    echo "<H3>Update config info for $IPADDR</H3>"
    if [ -f "$NETDIR/firstmac.txt" ]; then 
      FIRSTMAC=`readFile $NETDIR/firstmac.txt`
      FMACDIR="$SIM_MACDATAB/$FIRSTMAC"
      if [ -f "$FMACDIR/skip-arpdiscovery" ]; then
        echo "<A HREF=$SCRIPT_NAME?config+arpinfo_poll+$IPADDR+$NETWORK>poll arpinfo</A> -"
      else
        echo "<A HREF=$SCRIPT_NAME?config+arpinfo_skip+$IPADDR+$NETWORK>skip arpinfo</A> -"
      fi
    fi
    echo "<TABLE>
          <FORM method=post Action=$SCRIPT_NAME?config+config_update+$IPADDR+$NETWORK>
          <TR><TD>IP addres:</TD>
              <TD>$IPADDR</TD>
              <TD><INPUT NAME=ipaddr SIZE=30 VALUE=$IPADDR></TD></TR>
          <TR><TD>Dhcp macaddr:</TD>
              <TD>$DHCPMAC</TD>
              <TD><INPUT NAME=dhcpmac SIZE=30 VALUE=$DHCPMAC></TD></TR>
          <TR><TD>Type</TD>
              <TD>$SIPMANRECTYPE</TD>
              <TD><select name=sipmanrectype size=1>
                  <option value=$SIPMANRECTYPE>$SIPMANRECTYPE</option>"
    for NUM in 1 2 3 4 5 6 7 8 
    do
      echo "<option value=${RECNAME[$NUM]}>(${RECTYPESTR[$NUM]}) ${RECNAME[$NUM]}</option>"
    done
    echo "</SELECT></TD></TR>
          <TR><TD>Address type:</TD>
              <TD>$NODETYPE</TD>
              <TD><SELECT NAME=nodetype SIZE=1>
                  <OPTION VALUE=$NODETYPE>$NODETYPE</OPTION>"
    for VAR in ${NETNAME[*]}
    do
      echo "<OPTION VALUE=$VAR>$VAR</OPTION>"
    done
    echo "</SELECT></TD></TR> 
          <TR><TD>Management type</TD>
              <TD>$MANAGEMENTTYPE</TD>
              <TD><SELECT NAME=managementtype SIZE=1>
                  <OPTION VALUE=$MANAGEMENTTYPE>$MANAGEMENTTYPE</OPTION>"
    for VAR in ${MANTYPE[*]}
    do
      echo "<OPTION VALUE=$VAR>$VAR</OPTION>"
    done
    echo "</SELECT></TD></TR>
          <TR><TD>DNS hostname</TD>
              <TD>${DNSNAME[1]}</TD>
              <TD><INPUT NAME=dnshostname SIZE=30 VALUE=${DNSNAME[1]}></TD></TR>
          <TR><TD>DNS domain</TD>
              <TD>${DNSNAME[2]}</TD>
              <TD><select name=dnsdomain size=1>
              <option value=${DNSNAME[2]}>${DNSNAME[2]}</option>"
          cat $SIM_DNSDOMAINS | while read DTYPE TDOMAIN DDESCR
          do
            if [ "$DTYPE" = "int" ]; then
              echo "<option value=$TDOMAIN>$TDOMAIN ($DDESCR)</option>"
            fi
          done
    echo "</SELECT></TD></TR>
          <TR><TD>Comment:</TD><TD></TD>
              <TD><INPUT NAME=comment SIZE=50 VALUE=\"$COMMENT\"></TD></TR>
                                                                                                                             
          </TABLE>
          <INPUT TYPE=submit Value=Update>
          </FORM>
          <HR>
          <H3>Additional dns reccords</H3>
          <TABLE>
          <TR BGCOLOR=#DDDDDD><TD>Type</TD><TD>Name</TD><TD>Action</TD></TR>"

          for FILE in `ls $NETDIR/dnsrec-* 2>/dev/null` `ls $SIM_DNSDIR/cname-${DNSNAME[1]}.${DNSNAME[2]}-* 2>/dev/null`
          do
            DNSREC=( `cat $FILE` )
            echo "<TR><TD>${DNSREC[0]}</TD>
                      <TD>${DNSREC[1]}.${DNSREC[2]}</TD>
                      <TD><A HREF=$SCRIPT_NAME?config+remdnsrec+$IPADDR+$NETWORK+${DNSREC[1]}.${DNSREC[2]}>Remove</A>"
          done

    echo "</TABLE>
          <HR>
          <H3>Add an additional dns reccord.</H3>
          <TABLE>
          <FORM method=post Action=$SCRIPT_NAME?config+adddnsrec+$IPADDR+$NETWORK>
          <TR><TD>New host name:</TD><TD><INPUT NAME=dnshostname SIZE=30></TD></TR>
          <TR><TD>DNS domain</TD>
          <TD><select name=dnsdomain size=1>
              <option value=${DNSNAME[2]}>${DNSNAME[2]}</option>"
          cat $SIM_DNSDOMAINS | while read DTYPE TDOMAIN DDESCR
          do
            if [ "$DTYPE" = "int" ]; then
              echo "<option value=$TDOMAIN>$TDOMAIN ($DDESCR)</option>"
            fi
          done
          echo "</SELECT></TD></TR>
          <TR><TD>Reccord type:</TD><TD>
            <INPUT TYPE=radio NAME=rectype VALUE=A><B>A</B>
            <INPUT TYPE=radio NAME=rectype VALUE=CNAME> <B>CNAME</B><P>
            </TD></TR>
          </TABLE>
          <INPUT TYPE=submit Value=Add>
          </FORM>
         "
  fi
}
removeEntry ()
{
  IPADDR=$1
  NETDIR=$SIM_IPDATAB/`echo $IPADDR | sed 's#\.#/#g'`
  if [ ! -d $NETDIR ]; then
    echo "$NETDIR not found."
  else
    echo "Removing $IPADDR"
    echo "<TABLE><TR><TD><PRE>"
    $SIM_SUDO $SIM_UPDATET $REMOTE_USER removeEntry "$IPADDR"
    echo "</PRE></TD></TR></TABLE>"
  fi
}
addDnsRec ()
{
  local IPADDR=$1
  NETDIR=$SIM_IPDATAB/`echo $IPADDR | sed 's#\.#/#g'`
  if [ ! -d $NETDIR ]; then
    echo "$NETDIR not found."
  else
    HOSTNAME=$FORM_dnshostname
    DOMAIN=$FORM_dnsdomain
    RECTYPE=$FORM_rectype
    if [ "$RECTYPE" = "" ]; then
      RECTYPE=A
    fi
    if [ "$HOSTNAME" = "" ]; then
      echo "No hostname specified"
    else
      $SIM_SUDO $SIM_UPDATET $REMOTE_USER addDnsReccord "$IPADDR" "$RECTYPE $HOSTNAME $DOMAIN"
    fi
  fi
}

remDnsRec ()
{
  local IPADDR=$1
  local DNSREC=$2
  NETDIR=$SIM_IPDATAB/`echo $IPADDR | sed 's#\.#/#g'`
  if [ ! -d $NETDIR ]; then
    echo "$NETDIR not found."
  else
    echo "<PRE>"
    echo "$REMOTE_USER"
    $SIM_SUDO $SIM_UPDATET $REMOTE_USER remDnsRec "$IPADDR" "$DNSREC"
    echo "</PRE>"
  fi
}

updateNode ()
{
  local IPADDR=$1
  NETDIR=$SIM_IPDATAB/`echo $IPADDR | sed 's#\.#/#g'`
  if [ ! -d $NETDIR ]; then
    echo "$NETDIR not found."
  else
    NODETYPE=`readFile $NETDIR/nodetype.txt`
    SIPMANRECTYPE=`readFile $NETDIR/sipmanrectype.txt`
    MANAGEMENTTYPE=`readFile $NETDIR/managementtype.txt`
    SNMPMAC=`readFile $NETDIR/snmpmac.txt`
    DHCPMAC=`readFile $NETDIR/dhcpmacaddr.txt`
    NSTATUS=`readFile $NETDIR/pollstatus.txt`
    DNSNAME=( `readFile $NETDIR/dnsname.txt` )
    HOSTNAME=`readFile $NETDIR/hostname.txt`
    SNMPOID=`readFile $NETDIR/snmpoid.txt`
    INTNUM=`readFile $NETDIR/intnum.txt`
    COMM=`readFile $NETDIR/$DIR/snmpcomm.txt`
    CFGDATE=`readFile $NETDIR/$DIR/snmpinfodate.txt`
    COMMENT="`readFile $NETDIR/$DIR/comment.txt`"
    echo "<TABLE><TR><TD><PRE>"
    if [ "$IPADDR" != "$FORM_ipaddr" ]; then
      $SIM_SUDO $SIM_UPDATET $REMOTE_USER modIpAddr "$IPADDR" "$FORM_ipaddr"
      IPADDR=$FORM_ipaddr
    fi
    if [ "$SIPMANRECTYPE" != "$FORM_sipmanrectype" ]; then
      $SIM_SUDO $SIM_UPDATET $REMOTE_USER modSipmanRectype "$IPADDR" "$FORM_sipmanrectype"
    fi
    if [ "$DHCPMAC" != "$FORM_dhcpmac" ]; then
      $SIM_SUDO $SIM_UPDATET $REMOTE_USER modDhcpmac "$IPADDR" "$FORM_dhcpmac"
    fi
    if [ "$NODETYPE" != "$FORM_nodetype" ]; then
      $SIM_SUDO $SIM_UPDATET $REMOTE_USER modNodeType "$IPADDR" "$FORM_nodetype"
    fi
    if [ "$MANAGEMENTTYPE" != "$FORM_managementtype" ]; then
      $SIM_SUDO $SIM_UPDATET $REMOTE_USER modManType "$IPADDR" "$FORM_managementtype"
    fi
    if [ "${DNSNAME[1]}" != "$FORM_dnshostname" ] || [ "${DNSNAME[2]}" != "$FORM_dnsdomain" ]; then
      $SIM_SUDO $SIM_UPDATET $REMOTE_USER modDnsName "$IPADDR" "$FORM_dnshostname" "$FORM_dnsdomain"
    fi
    if [ "$COMMENT" != "$FORM_comment" ]; then
      $SIM_SUDO $SIM_UPDATET $REMOTE_USER modComment "$IPADDR" "$FORM_comment"
    fi
    echo "</PRE></TD></TR></TABLE>"
  fi
}

dispOidInfo ()
{
local IPADDR=$1
NETDIR=$SIM_IPDATAB/`echo $IPADDR | sed 's#\.#/#g'`
COMMUNITY=`readFile $NETDIR/snmpcomm.txt`
SYSNAME=`$SIM_SNMPGET -v1 -Ovq -c $COMMUNITY $IPADDR .1.3.6.1.2.1.1.5.0`
SYSDESCR=`$SIM_SNMPGET -v1 -Onvq -c $COMMUNITY $IPADDR .1.3.6.1.2.1.1.1.0`
SYSOID=`$SIM_SNMPGET -v1 -Onvq -c $COMMUNITY $IPADDR .1.3.6.1.2.1.1.2.0`
DESCR=`cat $SIM_OIDHELPD/$SYSOID/shortDescription`
ADDRTYPE=`cat $SIM_OIDHELPD/$SYSOID/category`
VENDOR=`cat $SIM_OIDHELPD/$SYSOID/vendor`
DNSPREFIX=`cat $SIM_OIDHELPD/$SYSOID/dnsPrefix`
if [ -f $SIM_OIDHELPD/$SYSOID/isSwitch ]; then
  ISSWITCH=yes
fi
if [ -f $SIM_OIDHELPD/$SYSOID/getArp ]; then
  GETARP=yes
fi
if [ -f $SIM_OIDHELPD/$SYSOID/firstMacIsName ]; then
  ISFMACNAME=yes
fi

echo "<H3>Add Oid info for Oid $SYSOID</H3>
          <TABLE>
          <FORM method=post Action=$SCRIPT_NAME?config+addoidinfo+$IPADDR+$NETWORK>
          <TR><TD>OID:</TD><TD>$SYSOID</TD></TR>
          <INPUT NAME=\"sysoid\" TYPE=hidden VALUE=\"$SYSOID\">
          <TR><TD>Name:</TD><TD>$SYSNAME</TD></TR>
          <TR><TD VALIGN=top>Descr:</TD><TD>$SYSDESCR</TD></TR>
          <TR><TD>OID hint:</TD><TD>$HELPOIDINFO</TD></TR>
          <TR><TD>Type descr:</TD><TD><INPUT NAME=\"oidinfo\" VALUE=\"$DESCR\" SIZE=30></TD></TR>
          <TR><TD>Oid type:</TD><TD>
             <SELECT NAME=\"oidtype\" SIZE=1>
	     <OPTION VALUE=\"$ADDRTYPE\">$ADDRTYPE</OPTION>"
    for VAR in ${NETNAME[*]}
    do
      echo "<OPTION VALUE=$VAR>$VAR</OPTION>"
    done
    echo "</SELECT></TD></TR>
          <TR><TD>DNS prefix:</TD><TD><INPUT NAME=\"oiddir\" VALUE=\"$DNSPREFIX\" SIZE=30></TD></TR>
          <TR><TD>Vendor:</TD><TD><INPUT NAME=\"oidvendor\" VALUE=\"$VENDOR\" SIZE=30></TD></TR>
          <TR><TD>IsSwitch:</TD><TD>"
    if [ "$ISSWITCH" = "yes" ]; then
      echo "<INPUT NAME=\"isSwitch\" TYPE=radio VALUE=yes checked>Yes&nbsp;
            <INPUT NAME=\"isSwitch\" TYPE=radio VALUE=no>No&nbsp;"
    else
      echo "<INPUT NAME=\"isSwitch\" TYPE=radio VALUE=yes>Yes&nbsp;
            <INPUT NAME=\"isSwitch\" TYPE=radio VALUE=no checked>No&nbsp;"
    fi
    echo "</TD></TR>
          <TR><TD>GetArp:</TD><TD>"
    if [ "$GETARP" = "yes" ]; then
      echo "<INPUT NAME=\"getArp\" TYPE=radio VALUE=yes checked>Yes&nbsp;
            <INPUT NAME=\"getArp\" TYPE=radio VALUE=no>No&nbsp;"
    else
      echo "<INPUT NAME=\"getArp\" TYPE=radio VALUE=yes>Yes&nbsp;
            <INPUT NAME=\"getArp\" TYPE=radio VALUE=no checked>No&nbsp;"
    fi
    echo "</TD></TR>
          <TR><TD>firstMac is name:</TD><TD>"
    if [ "$ISFMACNAME" = "yes" ]; then
      echo "<INPUT NAME=\"firstMacIsName\" TYPE=radio VALUE=yes checked>Yes&nbsp;
            <INPUT NAME=\"firstMacIsName\" TYPE=radio VALUE=no>No&nbsp;"
    else
      echo "<INPUT NAME=\"firstMacIsName\" TYPE=radio VALUE=yes>Yes&nbsp;
            <INPUT NAME=\"firstMacIsName\" TYPE=radio VALUE=no checked>No&nbsp;
            (use this for devices with identical mac adresses (like fwsm nodes))"
    fi
    echo "</TD></TR>
          </TABLE>
          <INPUT TYPE=submit Value=Update>
          </FORM>
     "
}
addOidInfo ()
{
  local IPADDR=$1
  NETDIR=$SIM_IPDATAB/`echo $IPADDR | sed 's#\.#/#g'`
  OIDNUM=$FORM_sysoid 
  if [ "$OIDNUM" = "" ]; then
    echo "No oidnum found."
  elif [ "$FORM_oidinfo" = "" ]; then
    echo "No FORM_oidinfo found."
  elif [ "$FORM_oidtype" = "" ]; then
    echo "No FORM_oidtype found."
  elif [ "$FORM_oiddir" = "" ]; then
    echo "No FORM_oiddir found."
  elif [ "$FORM_oidvendor" = "" ]; then
    echo "No FORM_oidvendor found."
  else
    OIDINFO=`echo $FORM_oidinfo| sed 's/ /_/g'`
    OIDVENDOR=`echo $FORM_oidvendor | sed 's/ /_/g'`
    ISSWITCH=$FORM_isSwitch
    GETARP=$FORM_getArp
    ISFMACNAME=$FORM_firstMacIsName
    #if [ !-d "$SIM_OIDHELPD/$SYSOID" ]; then
    #  mkdir "$SIM_OIDHELPD/$SYSOID"
    #fi
    mkdir -p $SIM_OIDHELPD/$OIDNUM
    echo "$OIDINFO" > $SIM_OIDHELPD/$OIDNUM/shortDescription
    echo "$FORM_oiddir" > $SIM_OIDHELPD/$OIDNUM/category
    echo "$FORM_oidtype" > $SIM_OIDHELPD/$OIDNUM/dnsPrefix
    echo "$OIDVENDOR" > $SIM_OIDHELPD/$OIDNUM/vendor
    if [ "$ISSWITCH" = "yes" ]; then
      echo "yes" > $SIM_OIDHELPD/$OIDNUM/isSwitch
    else
      if [ -f $SIM_OIDHELPD/$OIDNUM/isSwitch ]; then
        rm $SIM_OIDHELPD/$OIDNUM/isSwitch
      fi
    fi
    if [ "$GETARP" = "yes" ]; then
      echo "yes" > $SIM_OIDHELPD/$OIDNUM/getArp
    else
      if [ -f $SIM_OIDHELPD/$OIDNUM/getArp ]; then
        rm $SIM_OIDHELPD/$OIDNUM/getArp
      fi
    fi
    if [ "$ISFMACNAME" = "yes" ]; then
      echo "yes" > $SIM_OIDHELPD/$OIDNUM/firstMacIsName
    else
      if [ -f $SIM_OIDHELPD/$OIDNUM/firstMacIsName ]; then
        rm $SIM_OIDHELPD/$OIDNUM/firstMacIsName
      fi
    fi

    # update and display config.
    echo "<PRE>"
    $SIM_SUDO $SIM_IMPORTINFO testNode $IPADDR
    echo "</PRE>"
    echo "<A HREF=$SCRIPT_NAME?mon+nodestatus+$IPADDR+$NETWORK>Display node info</A>"
  fi
}
addWhois ()
{
IPADDR=$1
  echo "<TABLE><TR><TD><PRE>"
  whois $IPADDR | while read OPTION VALUE
  do
    echo "$OPTION $VALUE"
    case `echo $OPTION | tr '[A-Z]' '[a-z]'` in
      (inetnum:|netrange:) NETSTART=`echo $VALUE | awk '{ print $1 }'`
                 NETSTOP=`echo $VALUE | awk '{ print $3 }'`
      ;;
      (netname:) NETNAME=$VALUE ;;
      (descr:|orgname:)   
          if [ "$DESCR" = "" ]; then
            DESCR="$VALUE"
          fi
       ;;
      (country:) COUNTRY="$VALUE" ;;
      (source:|updated:|e-mail)
          TESTSTR="`printLongIp $NETSTART` `printLongIp $NETSTOP`"
          if [ "$TESTSTR" != " " ] && [ "`grep "$TESTSTR" $SIM_DNSPREFIXES`" != "" ]; then
            echo "<HR></PRE></TD></TR></TABLE>
                  Prefix already defined for the range $TESTSTR"
            exit 4
          else
            echo "</PRE></TD></TR></TABLE>
                <HR>
                <TABLE>
                <FORM method=post Action=$SCRIPT_NAME?config+addwhoisentry+$IPADDR+$NETWORK>
                <TR><TD>Range</TD>
                    <TD><INPUT NAME=netstart Size=16 Type=text Value=$NETSTART>
                        <INPUT NAME=netstop Size=16 Type=text Value=$NETSTOP></TD></TR>
                <TR><TD>Description</TD>
                    <TD><INPUT NAME=descr Size=60 Type=text Value=\"$DESCR\"></TD></TR>
                <TR><TD>DNS prefix</TD>
                    <TD><INPUT NAME=dnsprefix Size=60 Type=text Value=`echo $NETNAME.$COUNTRY | tr '[A-Z]' '[a-z]'`></TD></TR>
                </TABLE>
            <INPUT TYPE=submit Value=Add>
            </FORM>"
            exit 5
          fi
      ;;
    esac
  done
  if [ "$?" = "0" ]; then
    # if no info could be found t fill the table, present an empty one.
    echo "</PRE></TD></TR></TABLE>
          <HR>
          <TABLE>
          <FORM method=post Action=$SCRIPT_NAME?config+addwhoisentry+$IPADDR+$NETWORK>
          <TR><TD>Range</TD>
              <TD><INPUT NAME=netstart Size=16 Type=text>
                  <INPUT NAME=netstop Size=16 Type=text></TD></TR>
          <TR><TD>Description</TD>
              <TD><INPUT NAME=descr Size=60 Type=text></TD></TR>
          <TR><TD>DNS prefix</TD>
              <TD><INPUT NAME=dnsprefix Size=60 Type=text></TD></TR>
          </TABLE>
          <INPUT TYPE=submit Value=Add>
          </FORM>"
  fi
}
displayNode ()
{
  local IPADDR=$1
  SHOWMENU=no
  . $SIM_MONITORT nodestatus $IPADDR
}
# ------------------------------- Main --------------------------------
LEVEL=`$SIM_TESTLEVELT address $REMOTE_USER`
                                                                                                                             
#echo "<A HREF=$SCRIPT_NAME?mon+nodestatus+$2+$3>Nodestatus</A> -<HR>"

# echo "$1-$2-$3-$4<HR>"

if [ "$1" = "" ]; then
  ACTION=none
else
  ACTION=$1
fi
if [ "$2" = "" ]; then
  IPADDR=none
else
  IPADDR=$2
fi
if [ "$3" = "" ]; then
  NETWORK=none
else
  NETWORK=$3
fi
                                                                                                                             
if [ "$ACTION" = "addwhois" ]; then
  IPADDR=$2
  addWhois $IPADDR
elif [ "$ACTION" = "dispoidinfo" ]; then
  dispOidInfo $IPADDR
elif [ "$ACTION" = "addoidinfo" ]; then
  addOidInfo $IPADDR
elif [ "$ACTION" = "removeEntry" ]; then
  removeEntry $IPADDR
elif [ "$ACTION" = "addwhoisentry" ]; then
  if [ "$FORM_netstart" != "" ]; then
    TESTSTR="`printLongIp $FORM_netstart` `printLongIp $FORM_netstop`"
    if [ "`grep "$TESTSTR" $SIM_DNSPREFIXES`" = "" ]; then
      echo "Adding prefix $FORM_dnsprefix for nodes between $FORM_netstart and $FORM_netstop"
      echo "DNSPREFIX `printLongIp $FORM_netstart` `printLongIp $FORM_netstop` $FORM_dnsprefix $FORM_descr" >> $SIM_DNSPREFIXES
    else
      echo "Definition for $FORM_netstart - $FORM_netstop already present."
    fi
  fi
elif [ "$ACTION" = "arpinfo_poll" ] || [ "$ACTION" = "arpinfo_skip" ]; then
  case $ACTION in
    (arpinfo_poll)  SKIPACTION=remove ;;
    (arpinfo_skip)  SKIPACTION=add ;;
  esac
  $SIM_SUDO $SIM_UPDATET $REMOTE_USER modArpInfoPoll $IPADDR $SKIPACTION
  displayNode $IPADDR
elif [ "$ACTION" = "adddnsrec" ]; then
  IPADDR=$2
  addDnsRec $IPADDR
  . $SIM_CONFIGT config $IPADDR $NETWORK
elif [ "$ACTION" = "remdnsrec" ]; then
# echo "=$1=$2=$3=$4=$5="
  IPADDR=$2
  DNSREC=$4
  remDnsRec $IPADDR $DNSREC
  . $SIM_CONFIGT config $IPADDR $NETWORK
elif [ "$ACTION" = "config" ]; then
  IPADDR=$2
  dispNodeConfig $IPADDR $NETWORK
elif [ "$ACTION" = "config_update" ]; then
  IPADDR=$2
  updateNode $IPADDR
  displayNode $IPADDR
elif [ "$ACTION" = "setManDomain" ]; then
  MANDOMAIN=$2
  echo "$MANDOMAIN" > $SIM_USRMANDOM
  echo "Management domain for $REMOTE_USER set to `cat $SIM_USRMANDOM`."
else
  echo "<H2>Oops config action $ACTION not defined</H2>"
fi

# temporary files removen if they exist.
for FILE in $TMPFILE1 $TMPFILE2
do
  if [ -f $FILE ]; then
    rm $FILE
  fi
done
